
		 var ajaxcommt = function(options){
		 	var _self= this;
		 	var defaults = {
		 		form:0,  //表单元素
		 		message:0, //显示消息区域
		 		validate:function(){},
		 		submitbtn:0,
		 		content:0,
		 		code:0,
		 		comments:0,
		 		url:'',
		 	};
		 	$.extend(defaults,options);
		 	
		 	
		 	var ready=false;

		 	defaults.content.bind("focus keyup input paste",function(){
		 			var content = defaults.content.val();
		 		    content = content.replace(defaults.content.attr('placeholder'), "");
	                var num = _self.getLength(content);
	                    left = 320 - num;
	                if(left>=0){
	                    defaults.message.html("<ins>还可以输入<strong>"+left+"</strong>字</ins>");
	                }else{
	                    defaults.message.html("<ins class='tips tips_icon_error'>评论已超过<b>"+Math.abs(left)+"</b>字</ins>");
	                }
	                ready = !(num < 1 || num > 320);
		 	});

		 	defaults.submitbtn.click(function(){
		 			defaults.validate();
		 			_self.validate();
		 			if(!ready)return;

		 			$.ajax({
						async:true,
						type:"post",
						url:defaults.url,
						data:defaults.form.serialize(),
						dataType:"json",
						beforeSend:function(){
							ready = false;
							defaults.message.html('<ins class="tips_loading">正在发送......</ins>');
						},
						success:function(data, status){
							if(data.status == '200'){
									defaults.message.html('<ins class="tips tips_icon_success">感谢评论.</ins>');
									var ap_text = '<dl><dt><span class="re_username">匿名人士</span><span class="re_area"></span><span class="datetime">发表于 '+(new Date()).toLocaleTimeString()+'</span></dt><dd class="re_text">'+defaults.content.val()+'</dd><dd class="re_mark"><span></span></dd></dl>';
									defaults.content.val("");
									defaults.code.val("");
									defaults.comments.prepend(ap_text).parent().fadeIn();
									setTimeout(function(){defaults.content.focus();defaults.code.next().click();},3000);
								return;
							}
							if(data.status == '400'){
									defaults.message.html('<ins class="tips tips_icon_error">'+data.message+'</ins>');
							}
						}
					});

		 	});

		 	_self.validate = function(){
		 		var wcontent = $.trim(defaults.content.val());
					wcontent = wcontent.replace(defaults.content.attr('placeholder'), "");
					var num = _self.getLength(wcontent);
					if(num < 1 || num > 320){
                        defaults.message.html('<ins class="tips tips_icon_error">评论不能为空</ins>');
                        defaults.content.focus();
                        ready = false;
                        return;
					}else{
						ready = true;
					}
					var wseccode = $.trim(defaults.code.val());
                    if(wseccode.length < 1){
                        defaults.message.html('<ins class="tips tips_icon_error">请填写验证码</ins>');
                        defaults.code.focus();
                        ready = false;
                        return;
                    }else{
						ready = true;
					}
		 	}


		 	_self.getLength=function(q, g) {
					var trim = function(h) {
							try {
								return h.replace(/^\s+|\s+$/g, "")
							} catch (j) {
								return h
							}
						},
						byteLength = function(b) {
							if (typeof b == "undefined") {
								return 0
							}
							var a = b.match(/[^\x00-\x80]/g);
							return (b.length + (!a ? 0 : a.length))
						};

					g = g || {};
					g.max = g.max || 320;
					g.min = g.min || 41;
					g.surl = g.surl || 20;
					var p = trim(q).length;
					if (p > 0) {
						var j = g.min,
							s = g.max,
							b = g.surl,
							n = q;
						var r = q.match(/(http|https):\/\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z\$\.\+\!\_\*\(\)\/\,\:;@&=\?~#%]*)*/gi) || [];
						var h = 0;
						for (var m = 0, p = r.length; m < p; m++) {
							var o = byteLength(r[m]);
							if (/^(http:\/\/t.cn)/.test(r[m])) {
								continue
							} else {
								if (/^(http:\/\/)+(t.sina.com.cn|t.sina.cn)/.test(r[m]) || /^(http:\/\/)+(weibo.com|weibo.cn)/.test(r[m])) {
									h += o <= j ? o : (o <= s ? b : (o - s + b))
								} else {
									h += o <= s ? b : (o - s + b)
								}
							}
							n = n.replace(r[m], "")
						}
						return Math.ceil((h + byteLength(n)) / 2)
					} else {
						return 0
					}
				}
		 	
		 }



